/** <a href="http://www.cpupk.com/decompiler">Eclipse Class Decompiler</a> plugin, Copyright (c) 2017 Chen Chao. **/
package com.minierp.view;

import com.minierp.bean.BusinessBillBean;
import com.minierp.bean.BusinessBillItemBean;
import com.minierp.helper.EncCommonHelper;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Map;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.Region;
import org.springframework.web.servlet.view.document.AbstractExcelView;

public class BusinessBillExcelView extends AbstractExcelView {
	public void buildExcelDocument(Map model, HSSFWorkbook workbook,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		response.reset();
		response.setContentType("APPLICATION/vnd.ms-excel");
		response.setHeader("Content-Disposition",
				"attachment;filename=\"BusinessBill.xls\"");
		HSSFSheet sheet = workbook.createSheet("list");
		BusinessBillBean bean = (BusinessBillBean) model.get("record");
		SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
		HSSFFont titltFont = workbook.createFont();
		titltFont.setFontHeightInPoints(16);
		titltFont.setBoldweight(700);
		HSSFFont boldFont = workbook.createFont();
		boldFont.setBoldweight(700);
		HSSFCellStyle titleCellStyle = workbook.createCellStyle();
		titleCellStyle.setFont(titltFont);
		titleCellStyle.setAlignment(2);
		titleCellStyle.setVerticalAlignment(1);
		HSSFCellStyle boldCellStyle = workbook.createCellStyle();
		boldCellStyle.setFont(boldFont);
		HSSFCellStyle norStyle = workbook.createCellStyle();
		norStyle.setBorderBottom(1);
		norStyle.setBorderTop(1);
		norStyle.setBorderLeft(1);
		norStyle.setBorderRight(1);
		HSSFCellStyle boldStyle = workbook.createCellStyle();
		boldStyle.setFont(boldFont);
		boldStyle.setBorderBottom(1);
		boldStyle.setBorderTop(1);
		boldStyle.setBorderLeft(1);
		boldStyle.setBorderRight(1);
		HSSFCellStyle rightStyle = workbook.createCellStyle();
		rightStyle.setAlignment(3);
		rightStyle.setBorderBottom(1);
		rightStyle.setBorderTop(1);
		rightStyle.setBorderLeft(1);
		rightStyle.setBorderRight(1);
		byte colNum = 9;
		byte rowIndex = 0;
		HSSFRow r = sheet.createRow(rowIndex);
		HSSFCell c = r.createCell(0);

		for (int deliverDate = 1; deliverDate < colNum; ++deliverDate) {
			r.createCell((short) deliverDate);
		}

		c.setCellStyle(titleCellStyle);
		c.setCellValue(new HSSFRichTextString("业务单"));
		sheet.addMergedRegion(new Region(0, 0, 0, (short) (colNum - 1)));
		int arg25 = rowIndex + 1;
		r = sheet.createRow(arg25);
		c = r.createCell(0);
		c.setCellStyle(boldCellStyle);
		c.setCellValue(new HSSFRichTextString("单号"));
		c = r.createCell(1);
		r.createCell(2);
		c.setCellValue(new HSSFRichTextString(bean.getBusinessBill()
				.getBillCode()));
		sheet.addMergedRegion(new Region(arg25, 1, arg25, 2));
		c = r.createCell(3);
		c.setCellStyle(boldCellStyle);
		c.setCellValue(new HSSFRichTextString("订货单位"));
		c = r.createCell(4);
		r.createCell(5);
		c.setCellValue(new HSSFRichTextString(bean.getClientName()));
		sheet.addMergedRegion(new Region(arg25, 4, arg25, 5));
		c = r.createCell(6);
		c.setCellStyle(boldCellStyle);
		c.setCellValue(new HSSFRichTextString("订货日期"));
		c = r.createCell(7);
		r.createCell(8);
		c.setCellValue(new HSSFRichTextString(sf.format(bean.getBusinessBill()
				.getOrderDate())));
		sheet.addMergedRegion(new Region(arg25, 7, arg25, 8));
		++arg25;
		r = sheet.createRow(arg25);
		c = r.createCell(0);
		c.setCellStyle(boldCellStyle);
		c.setCellValue(new HSSFRichTextString("联系人"));
		c = r.createCell(1);
		r.createCell(2);
		c.setCellValue(new HSSFRichTextString(bean.getBusinessBill()
				.getLinkman()));
		sheet.addMergedRegion(new Region(arg25, 1, arg25, 2));
		c = r.createCell(3);
		c.setCellStyle(boldCellStyle);
		c.setCellValue(new HSSFRichTextString("电话"));
		c = r.createCell(4);
		r.createCell(5);
		c.setCellValue(new HSSFRichTextString(bean.getBusinessBill().getPhone()));
		sheet.addMergedRegion(new Region(arg25, 4, arg25, 5));
		c = r.createCell(6);
		c.setCellStyle(boldCellStyle);
		c.setCellValue(new HSSFRichTextString("交货日期"));
		c = r.createCell(7);
		r.createCell(8);
		String arg26 = "";
		if (bean.getBusinessBill().getDeliverDate() != null) {
			arg26 = sf.format(bean.getBusinessBill().getDeliverDate());
		}

		c.setCellValue(new HSSFRichTextString(arg26));
		sheet.addMergedRegion(new Region(arg25, 7, arg25, 8));
		++arg25;
		r = sheet.createRow(arg25);
		c = r.createCell(0);
		c.setCellStyle(boldCellStyle);
		c.setCellValue(new HSSFRichTextString("地址"));
		c = r.createCell(1);
		r.createCell(2);
		r.createCell(3);
		r.createCell(4);
		r.createCell(5);
		r.createCell(6);
		r.createCell(7);
		r.createCell(8);
		c.setCellValue(new HSSFRichTextString(bean.getBusinessBill()
				.getAddress()));
		sheet.addMergedRegion(new Region(arg25, 1, arg25, 8));
		++arg25;
		r = sheet.createRow(arg25);
		c = r.createCell(0);

		for (int item = 1; item < colNum; ++item) {
			r.createCell((short) item);
		}

		c.setCellValue(new HSSFRichTextString(""));
		sheet.addMergedRegion(new Region(arg25, 0, arg25, (short) (colNum - 1)));
		++arg25;
		r = sheet.createRow(arg25);
		c = r.createCell(0);
		c.setCellStyle(boldStyle);
		c.setCellValue(new HSSFRichTextString("项目类型"));
		c = r.createCell(1);
		c.setCellStyle(boldStyle);
		c.setCellValue(new HSSFRichTextString("内容"));
		c = r.createCell(2);
		c.setCellStyle(boldStyle);
		c.setCellValue(new HSSFRichTextString("材质"));
		c = r.createCell(3);
		c.setCellStyle(boldStyle);
		c.setCellValue(new HSSFRichTextString("规格"));
		c = r.createCell(4);
		c.setCellStyle(boldStyle);
		c.setCellValue(new HSSFRichTextString("制作要求"));
		c = r.createCell(5);
		c.setCellStyle(boldStyle);
		c.setCellValue(new HSSFRichTextString("单位"));
		c = r.createCell(6);
		c.setCellStyle(boldStyle);
		c.setCellValue(new HSSFRichTextString("数量"));
		c = r.createCell(7);
		c.setCellStyle(boldStyle);
		c.setCellValue(new HSSFRichTextString("单价"));
		c = r.createCell(8);
		c.setCellStyle(boldStyle);
		c.setCellValue(new HSSFRichTextString("金额（元）"));
		++arg25;

		int examStr;
		for (examStr = 0; examStr < bean.getItems().size(); ++examStr) {
			BusinessBillItemBean arg27 = (BusinessBillItemBean) bean.getItems()
					.get(examStr);
			String os = arg27.getBusinessBillItem().getPriceType();
			String spec = arg27.getBusinessBillItem().getSpecification();
			if (os.equals("AREA") || os.equals("LENGTH")) {
				spec = spec
						+ " x "
						+ EncCommonHelper.parseBigDecimal(arg27
								.getBusinessBillItem().getAmount());
			}

			BigDecimal amount;
			if (!os.equals("AREA") && !os.equals("LENGTH")) {
				amount = arg27.getBusinessBillItem().getAmount();
			} else {
				amount = arg27.getBusinessBillItem().getSquareNum();
			}

			String unit = "";
			if (os.equals("AREA")) {
				unit = "平方米";
			} else if (os.equals("LENGTH")) {
				if (arg27.getBusinessBillItem().getLengType().equals("M")) {
					unit = "米";
				} else {
					unit = "公分";
				}
			} else if (os.equals("AMOUNT")) {
				unit = arg27.getBusinessBillItem().getUnit();
			}

			r = sheet.createRow(examStr + arg25);
			c = r.createCell(0);
			c.setCellStyle(norStyle);
			c.setCellValue(new HSSFRichTextString(arg27.getMakeTypeName()));
			c = r.createCell(1);
			c.setCellStyle(norStyle);
			c.setCellValue(new HSSFRichTextString(arg27.getBusinessBillItem()
					.getFinishedContent()));
			c = r.createCell(2);
			c.setCellStyle(norStyle);
			c.setCellValue(new HSSFRichTextString(arg27.getBusinessBillItem()
					.getProName()));
			c = r.createCell(3);
			c.setCellStyle(norStyle);
			c.setCellValue(new HSSFRichTextString(spec));
			c = r.createCell(4);
			c.setCellStyle(norStyle);
			c.setCellValue(new HSSFRichTextString(arg27.getBusinessBillItem()
					.getMakeRequire()));
			c = r.createCell(5);
			c.setCellStyle(norStyle);
			c.setCellValue(new HSSFRichTextString(unit));
			c = r.createCell(6);
			c.setCellStyle(rightStyle);
			c.setCellValue(new HSSFRichTextString(EncCommonHelper
					.parseBigDecimal(amount)));
			c = r.createCell(7);
			c.setCellStyle(rightStyle);
			c.setCellValue(new HSSFRichTextString(
					EncCommonHelper.parseBigDecimal(arg27.getBusinessBillItem()
							.getUnitPrice())));
			c = r.createCell(8);
			c.setCellStyle(rightStyle);
			c.setCellValue(new HSSFRichTextString(EncCommonHelper
					.parseBigDecimal(arg27.getBusinessBillItem().getCost())));
		}

		arg25 += bean.getItems().size();
		r = sheet.createRow(arg25);
		c = r.createCell(0);

		for (examStr = 1; examStr < colNum; ++examStr) {
			r.createCell((short) examStr);
		}

		sheet.addMergedRegion(new Region(arg25, 0, arg25, (short) (colNum - 1)));
		++arg25;
		r = sheet.createRow(arg25);
		c = r.createCell(0);
		c.setCellStyle(boldStyle);
		c.setCellValue(new HSSFRichTextString("折后金额"));
		c = r.createCell(1);
		c.setCellStyle(norStyle);
		r.createCell(2).setCellStyle(norStyle);
		c.setCellValue(new HSSFRichTextString(bean.getBusinessBill().getCost()
				+ "元"));
		sheet.addMergedRegion(new Region(arg25, 1, arg25, 2));
		c = r.createCell(3);
		c.setCellStyle(boldStyle);
		c.setCellValue(new HSSFRichTextString("业务员"));
		c = r.createCell(4);
		c.setCellStyle(norStyle);
		r.createCell(5).setCellStyle(norStyle);
		c.setCellValue(new HSSFRichTextString(bean.getBusinessBill()
				.getManagerName()));
		sheet.addMergedRegion(new Region(arg25, 4, arg25, 5));
		c = r.createCell(6);
		c.setCellStyle(boldStyle);
		c.setCellValue(new HSSFRichTextString("部门"));
		c = r.createCell(7);
		c.setCellStyle(norStyle);
		r.createCell(8).setCellStyle(norStyle);
		c.setCellValue(new HSSFRichTextString(bean.getDepartmentName()));
		sheet.addMergedRegion(new Region(arg25, 7, arg25, 8));
		++arg25;
		r = sheet.createRow(arg25);
		c = r.createCell(0);
		c.setCellStyle(boldStyle);
		c.setCellValue(new HSSFRichTextString("跟单员"));
		c = r.createCell(1);
		c.setCellStyle(norStyle);
		r.createCell(2).setCellStyle(norStyle);
		c.setCellValue(new HSSFRichTextString(bean.getBusinessBill()
				.getFollowerNameStr()));
		sheet.addMergedRegion(new Region(arg25, 1, arg25, 2));
		c = r.createCell(3);
		c.setCellStyle(boldStyle);
		c.setCellValue(new HSSFRichTextString("设计员"));
		c = r.createCell(4);
		c.setCellStyle(norStyle);
		r.createCell(5).setCellStyle(norStyle);
		c.setCellValue(new HSSFRichTextString(bean.getBusinessBill()
				.getDesignerNameStr()));
		sheet.addMergedRegion(new Region(arg25, 4, arg25, 5));
		c = r.createCell(6);
		c.setCellStyle(boldStyle);
		c.setCellValue(new HSSFRichTextString("业务来源"));
		c = r.createCell(7);
		c.setCellStyle(norStyle);
		r.createCell(8).setCellStyle(norStyle);
		c.setCellValue(new HSSFRichTextString(bean.getBusinessBill()
				.getIntroducerName()));
		sheet.addMergedRegion(new Region(arg25, 7, arg25, 8));
		++arg25;
		r = sheet.createRow(arg25);
		c = r.createCell(0);
		c.setCellStyle(boldStyle);
		c.setCellValue(new HSSFRichTextString("预付款"));
		c = r.createCell(1);
		c.setCellStyle(norStyle);
		r.createCell(2).setCellStyle(norStyle);
		c.setCellValue(new HSSFRichTextString(bean.getBusinessBill()
				.getImprest() + "元"));
		sheet.addMergedRegion(new Region(arg25, 1, arg25, 2));
		c = r.createCell(3);
		c.setCellStyle(boldStyle);
		c.setCellValue(new HSSFRichTextString("提货要求"));
		c = r.createCell(4);
		c.setCellStyle(norStyle);
		r.createCell(5).setCellStyle(norStyle);
		c.setCellValue(new HSSFRichTextString(bean.getBusinessBill()
				.getLadingRequire()));
		sheet.addMergedRegion(new Region(arg25, 4, arg25, 5));
		c = r.createCell(6);
		c.setCellStyle(boldStyle);
		c.setCellValue(new HSSFRichTextString("安装要求"));
		c = r.createCell(7);
		c.setCellStyle(norStyle);
		r.createCell(8).setCellStyle(norStyle);
		c.setCellValue(new HSSFRichTextString(bean.getBusinessBill()
				.getSetupRequire()));
		sheet.addMergedRegion(new Region(arg25, 7, arg25, 8));
		++arg25;
		r = sheet.createRow(arg25);
		c = r.createCell(0);
		c.setCellStyle(boldStyle);
		c.setCellValue(new HSSFRichTextString("备注"));
		c = r.createCell(1);
		c.setCellStyle(norStyle);
		r.createCell(2).setCellStyle(norStyle);
		r.createCell(3).setCellStyle(norStyle);
		r.createCell(4).setCellStyle(norStyle);
		r.createCell(5).setCellStyle(norStyle);
		r.createCell(6).setCellStyle(norStyle);
		r.createCell(7).setCellStyle(norStyle);
		r.createCell(8).setCellStyle(norStyle);
		c.setCellValue(new HSSFRichTextString(bean.getBusinessBill().getMark()));
		sheet.addMergedRegion(new Region(arg25, 1, arg25, 8));
		++arg25;
		r = sheet.createRow(arg25);
		c = r.createCell(0);

		for (examStr = 1; examStr < colNum; ++examStr) {
			r.createCell((short) examStr);
		}

		sheet.addMergedRegion(new Region(arg25, 0, arg25, (short) (colNum - 1)));
		++arg25;
		r = sheet.createRow(arg25);
		c = r.createCell(0);
		c.setCellStyle(boldCellStyle);
		c.setCellValue(new HSSFRichTextString("开单人"));
		c = r.createCell(1);
		r.createCell(2);
		c.setCellValue(new HSSFRichTextString(bean.getBusinessBill()
				.getCreaterName()));
		sheet.addMergedRegion(new Region(arg25, 1, arg25, 2));
		c = r.createCell(3);
		c.setCellStyle(boldCellStyle);
		c.setCellValue(new HSSFRichTextString("审核人"));
		c = r.createCell(4);
		r.createCell(5);
		String arg29 = "";
		if (bean.getBusinessBillExt().getExamined().equals("Y")) {
			arg29 = bean.getBusinessBillExt().getExaminerName();
		}

		c.setCellValue(new HSSFRichTextString(arg29));
		sheet.addMergedRegion(new Region(arg25, 4, arg25, 5));
		c = r.createCell(6);
		c.setCellStyle(boldCellStyle);
		c.setCellValue(new HSSFRichTextString("客户签名"));
		c = r.createCell(7);
		r.createCell(8);
		c.setCellValue(new HSSFRichTextString(""));
		sheet.addMergedRegion(new Region(arg25, 7, arg25, 8));
		sheet.setColumnWidth(1, 6000);
		sheet.setColumnWidth(4, 6000);
		ServletOutputStream arg28 = response.getOutputStream();
		workbook.write(arg28);
		arg28.flush();
		arg28.close();
	}
}